<?php

namespace App\Services\rx;

use App\Constants\ErrorCode;
use App\Exception\BusinessException;
use App\Model\Device;
use App\Model\DevicePort;
use App\Model\DeviceSignalLog;
use App\Model\Normal;
use App\Model\Order;
use Carbon\Carbon;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Logger\LoggerFactory;
use Hyperf\Redis\Redis;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
use Swoole\Server;

/**
 * 自行车充电桩通信服务
 */
class RxService
{
    // 命令码定义
    const CMD_LOGIN = 0x01;
    const CMD_LOGIN_REPLY = 0x81;
    const CMD_HEARTBEAT = 0x02;
    const CMD_HEARTBEAT_REPLY = 0x82;
    const CMD_CHARGE_PROGRESS = 0x03;
    const CMD_CHARGE_PROGRESS_REPLY = 0x83;
    const CMD_REMOTE_START = 0x84;
    const CMD_REMOTE_START_REPLY = 0x04;
    const CMD_REMOTE_STOP = 0x85;
    const CMD_REMOTE_STOP_REPLY = 0x05;
    const CMD_REPORT_ORDER = 0x06;
    const CMD_REPORT_ORDER_REPLY = 0x86;
    const CMD_CARD_START = 0x07;
    const CMD_CARD_START_REPLY = 0x87;
    const CMD_CARD_BALANCE = 0x08;
    const CMD_CARD_BALANCE_REPLY = 0x88;
    const CMD_ALARM = 0x09;
    const CMD_ALARM_REPLY = 0x89;
    const CMD_REBOOT = 0x0A;
    const CMD_REBOOT_REPLY = 0x8A;
    const CMD_SET_SERVER = 0x8B;
    const CMD_SET_SERVER_REPLY = 0x0B;
    const CMD_READ_PARAMS = 0x8C;
    const CMD_READ_PARAMS_REPLY = 0x0C;
    const CMD_SET_PARAMS = 0x8D;
    const CMD_SET_PARAMS_REPLY = 0x0D;
    const CMD_DC_START = 0x8E;
    const CMD_DC_START_REPLY = 0x0E;
    const CMD_BATTERY_STATUS = 0x0F;
    const CMD_BATTERY_STATUS_REPLY = 0x8F;
    const CMD_SWITCH_STATUS = 0x10;
    const CMD_SWITCH_STATUS_REPLY = 0x90;

    // 充电结束原因
    const STOP_REASON_OTHER = 0x00;
    const STOP_REASON_FULL = 0x01;
    const STOP_REASON_QUOTA = 0x02;
    const STOP_REASON_REMOTE = 0x03;
    const STOP_REASON_UNPLUGGED = 0x04;
    const STOP_REASON_PULLED = 0x05;
    const STOP_REASON_OVERVOLTAGE = 0x06;
    const STOP_REASON_UNDERVOLTAGE = 0x07;
    const STOP_REASON_OVERTEMP = 0x08;
    const STOP_REASON_METERING = 0x09;
    const STOP_REASON_SMOKE = 0x0A;
    const STOP_REASON_POWER_LIMIT = 0x0B;
    const STOP_REASON_TOTAL_POWER = 0x0C;
    const STOP_REASON_FIRE_ALARM = 0x0D;

    // 告警码
    const ALARM_OVERVOLTAGE = 1001;
    const ALARM_UNDERVOLTAGE = 1002;
    const ALARM_HIGHTEMP = 1003;
    const ALARM_METERING = 1004;
    const ALARM_STICKY = 1005;
    const ALARM_NO_LOAD = 1006;
    const ALARM_SMOKE = 1007;

    #[Inject]
    protected Device $device;

    #[Inject]
    protected DevicePort $devicePort;

    #[Inject]
    protected Order $order;

    protected LoggerInterface $logger;

    public function __construct(LoggerFactory $loggerFactory)
    {
        $this->logger = $loggerFactory->get('log', 'device');
    }


}
